<?php
class Model_UserRole extends Bcms_Db_Table
{
	 /**
     * table name
     *
     * @var string
     */
    protected $_name = 'user_role';
    
    /**
     * primary key
     * @var int
     */
    protected $_primary = 'id';
    
    /**
     * Update resources
     *  @param array $resourceArray
     *  @param int $Id
     * @return updated rows
     */
    public function updateAclResources($Id, $resourceArray)
    {
        $data['u_acl_resources'] = serialize($resourceArray);
        $where[] = $this->_db->quoteInto('id = ?', $Id);
        return $this->update($data, $where);
    }
    
    /*
     * Create Role
     */
    public function createRole($name, $detail)
    {
    	$identity = Bcms_Auth::getIdentity();
        $userId = $identity->id;
        $now = mktime(date('H'),date('i'),date('s'),date('m'),date('d'),date('Y'));
        $data = array(
		    'name' => $name,
		    'detail'  => $detail,
		    'userid' => $userId,
        	'reg_date' => $now,
		);
		
		$id = $this->insert($data);
		return $id;
    }
    
  	/*
     * Ajax UserName
     */
    public function getUserByName($name)
    {
    	$where = $this->_db->quoteInto('name = ?', $name);
    	$order = 'id';

		$row = $this->fetchRow($where, $order);
		return $row;
    }
    
    /**
     * Update Role
     */
	public function updateRole($id, $detail)
    {
        $page = $this->find($id)->current();
        if ($page) {
            $page->detail = $detail;
            return $page->save();
        }
        return false;
    }
    
    
    
    
}